import re
from typing import List
from _pytest.python import Function


# def pytest_collection_modifyitems(session, config, items: List[Function]):
#     """修改用例顺序"""
#     """
#     item.name  => 函数名
#     item.nodeid  => 路径/文件名.py::类名::函数名
#     """
#     order_li = ['test_2', 'test_3', 'test_1']
#     order_d = {i: name for name, i in enumerate(order_li)}
#
#     def func(e: Function):
#         """ 排序"""
#         file = re.search(r"/(\w+)\.py", e.nodeid).group(1)
#         num = order_d.get(file)
#         if num is None:
#             raise Exception("排序异常: 文件名与'order_li'不匹配")
#         return num
#
#     items.sort(key=func)
